import { EntitySchema, Ref } from '@mikro-orm/core';
import { Users } from './Users';

export class GeweChatAccount {
  id!: string;
  appid?: string;
  wxid?: string;
  expiredTime?: number;
  uuid?: number;
  owner?: Ref<Users>;
  headImgUrl?: string;
  nickName?: string;
  alias?: string;
  mobile?: string;
}

export const GeweChatAccountSchema = new EntitySchema({
  class: GeweChatAccount,
  properties: {
    id: { primary: true, type: 'string', columnType: 'bigint' },
    appid: { type: 'string', length: 100, nullable: true },
    wxid: { type: 'string', length: 100, nullable: true },
    expiredTime: { type: 'number', fieldName: 'expiredTime', nullable: true },
    uuid: { type: 'number', nullable: true },
    owner: {
      reference: 'm:1',
      entity: () => Users,
      ref: true,
      nullable: true,
      index: 'owner_user',
    },
    headImgUrl: { type: 'string', fieldName: 'headImgUrl', length: 500, nullable: true },
    nickName: { type: 'string', fieldName: 'nickName', length: 255, nullable: true },
    alias: { type: 'string', length: 255, nullable: true },
    mobile: { type: 'string', length: 255, nullable: true },
  },
});
